package com.carrent.demo.Service.Impl;

import com.carrent.demo.Domain.UserContract;
import com.carrent.demo.Mapper.CarsMapper;
import com.carrent.demo.Mapper.UserContractMapper;
import com.carrent.demo.Service.ContractService;
import com.carrent.demo.Service.UserContractService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;


@Service
public class UserContractServiceImpl implements UserContractService {

    @Autowired
    UserContractMapper userContractMapper;

    @Autowired
    ContractService contractService;

    @Autowired
    CarsMapper carsMapper;

    @Override
    public List<UserContract> getPage(Integer start, Integer pageSize, String name) {
        final List<UserContract> page = userContractMapper.getPage(start, pageSize, name);
        return page;
    }

    @Override
    public Integer getCount(String name) {
        return  contractService.getCount(name);
    }

    @Override
    public Boolean editUserContract(UserContract usercontract) {
        Integer id = userContractMapper.selectCarIdByContractId(usercontract.getContractId());
        final Double carPrice = carsMapper.getCarPrice(id);
        usercontract.setLeaPrice((usercontract.getConDay()+usercontract.getLeaDay())*carPrice);
        usercontract.setConRent(usercontract.getConDay()*carPrice);
        usercontract.setFacMoney(usercontract.getLeaPrice());

        usercontract.setWheRenewal(1);
        final Boolean aBoolean = userContractMapper.editUserContract(usercontract);
        return  aBoolean;
    }
    @Override
    public Boolean editReturn(Integer id, Integer status) {
        final Boolean aBoolean = userContractMapper.editReturn(id, status);
        return  aBoolean;
    }
}
